<?php
	class Morder extends CI_Model{
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		
		
		public function list_order($type)
		{
			
			$result=$this->db->query("SELECT o.id,o.code_order,o.`name`,o.payment,o.total,o.`status`,od.id_deal,od.`name` as deal,od.quantity,od.price,od.`status` as odstatus,(SELECT count(*) as sl FROM order_detail od1 WHERE od1.id_order=o.id) as sl 
										FROM `order` o ,order_detail od WHERE o.id=od.id_order AND o.status='$type' ORDER BY o.id DESC;");

			return $result->result_array();
		}
		
		public function get_orders()
		{
			$result=$this->db->query("SELECT count(*) as sl,o.`status` FROM `order` o GROUP BY o.`status`");
			return $result->result_array();
		}
		
		public function get_order_detail($oid)
		{
			$result=$this->db->query("SELECT o.code_order,o.`name` as aname,o.`email`,o.`phone`,o.`address`,o.`date`,o.`memo`,o.`amemo`,o.payment,o.total,o.`status` as ostatus,c.`name` as ncity,d.`name` as ndistrict,od.* 
				FROM `order` o ,order_detail od,city c,district d WHERE o.id=od.id_order AND od.id_order='$oid' AND o.city=c.id AND o.district=d.id");
			return $result->result_array();
		}
		
		public function changtype($oid,$type)
		{
			$result=$this->db->query("UPDATE `order` SET `status`='$type' WHERE (`id`='$oid');");

		}
		public function saveMemo($oid,$amemo)
		{
			$result=$this->db->query("UPDATE `order` SET `amemo`='$amemo' WHERE (`id`='$oid');");

		}
			
		
	}
?>